"use strict";
var e = require("../../chunks/three-platformize.js"),
  t = require("../../chunks/OrbitControls.js");
class s extends e.Loader {
  constructor(e) {
    super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register((function (e) {
      return new a(e)
    })), this.register((function (e) {
      return new d(e)
    })), this.register((function (e) {
      return new p(e)
    })), this.register((function (e) {
      return new l(e)
    })), this.register((function (e) {
      return new c(e)
    })), this.register((function (e) {
      return new u(e)
    })), this.register((function (e) {
      return new h(e)
    })), this.register((function (e) {
      return new o(e)
    })), this.register((function (e) {
      return new m(e)
    }))
  }
  load(t, s, n, r) {
    const o = this;
    let i;
    i = "" !== this.resourcePath ? this.resourcePath : "" !== this.path ? this.path : e.LoaderUtils.extractUrlBase(t), this.manager.itemStart(t);
    const a = function (e) {
        r ? r(e) : console.error(e), o.manager.itemError(t), o.manager.itemEnd(t)
      },
      l = new e.FileLoader(this.manager);
    l.setPath(this.path), l.setResponseType("arraybuffer"), l.setRequestHeader(this.requestHeader), l.setWithCredentials(this.withCredentials), l.load(t, (function (e) {
      try {
        o.parse(e, i, (function (e) {
          s(e), o.manager.itemEnd(t)
        }), a)
      } catch (e) {
        a(e)
      }
    }), n, a)
  }
  setDRACOLoader(e) {
    return this.dracoLoader = e, this
  }
  setDDSLoader() {
    throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')
  }
  setKTX2Loader(e) {
    return this.ktx2Loader = e, this
  }
  setMeshoptDecoder(e) {
    return this.meshoptDecoder = e, this
  }
  register(e) {
    return -1 === this.pluginCallbacks.indexOf(e) && this.pluginCallbacks.push(e), this
  }
  unregister(e) {
    return -1 !== this.pluginCallbacks.indexOf(e) && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this
  }
  parse(t, s, n, o) {
    let a;
    const l = {},
      c = {};
    if ("string" == typeof t) a = t;
    else {
      if (e.LoaderUtils.decodeText(new Uint8Array(t, 0, 4)) === f) {
        try {
          l[r.KHR_BINARY_GLTF] = new x(t)
        } catch (e) {
          return void(o && o(e))
        }
        a = l[r.KHR_BINARY_GLTF].content
      } else a = e.LoaderUtils.decodeText(new Uint8Array(t))
    }
    const u = JSON.parse(a);
    if (void 0 === u.asset || u.asset.version[0] < 2) return void(o && o(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));
    const h = new $(u, {
      path: s || this.resourcePath || "",
      crossOrigin: this.crossOrigin,
      requestHeader: this.requestHeader,
      manager: this.manager,
      ktx2Loader: this.ktx2Loader,
      meshoptDecoder: this.meshoptDecoder
    });
    h.fileLoader.setRequestHeader(this.requestHeader);
    for (let e = 0; e < this.pluginCallbacks.length; e++) {
      const t = this.pluginCallbacks[e](h);
      c[t.name] = t, l[t.name] = !0
    }
    if (u.extensionsUsed)
      for (let e = 0; e < u.extensionsUsed.length; ++e) {
        const t = u.extensionsUsed[e],
          s = u.extensionsRequired || [];
        switch (t) {
          case r.KHR_MATERIALS_UNLIT:
            l[t] = new i;
            break;
          case r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
            l[t] = new S;
            break;
          case r.KHR_DRACO_MESH_COMPRESSION:
            l[t] = new M(u, this.dracoLoader);
            break;
          case r.KHR_TEXTURE_TRANSFORM:
            l[t] = new v;
            break;
          case r.KHR_MESH_QUANTIZATION:
            l[t] = new y;
            break;
          default:
            s.indexOf(t) >= 0 && void 0 === c[t] && console.warn('THREE.GLTFLoader: Unknown extension "' + t + '".')
        }
      }
    h.setExtensions(l), h.setPlugins(c), h.parse(n, o)
  }
}

function n() {
  let e = {};
  return {
    get: function (t) {
      return e[t]
    },
    add: function (t, s) {
      e[t] = s
    },
    remove: function (t) {
      delete e[t]
    },
    removeAll: function () {
      e = {}
    }
  }
}
const r = {
  KHR_BINARY_GLTF: "KHR_binary_glTF",
  KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
  KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
  KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
  KHR_MATERIALS_IOR: "KHR_materials_ior",
  KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: "KHR_materials_pbrSpecularGlossiness",
  KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
  KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
  KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
  KHR_MATERIALS_VOLUME: "KHR_materials_volume",
  KHR_TEXTURE_BASISU: "KHR_texture_basisu",
  KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
  KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
  EXT_TEXTURE_WEBP: "EXT_texture_webp",
  EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression"
};
class o {
  constructor(e) {
    this.parser = e, this.name = r.KHR_LIGHTS_PUNCTUAL, this.cache = {
      refs: {},
      uses: {}
    }
  }
  _markDefs() {
    const e = this.parser,
      t = this.parser.json.nodes || [];
    for (let s = 0, n = t.length; s < n; s++) {
      const n = t[s];
      n.extensions && n.extensions[this.name] && void 0 !== n.extensions[this.name].light && e._addNodeRef(this.cache, n.extensions[this.name].light)
    }
  }
  _loadLight(t) {
    const s = this.parser,
      n = "light:" + t;
    let r = s.cache.get(n);
    if (r) return r;
    const o = s.json,
      i = ((o.extensions && o.extensions[this.name] || {}).lights || [])[t];
    let a;
    const l = new e.Color(16777215);
    void 0 !== i.color && l.fromArray(i.color);
    const c = void 0 !== i.range ? i.range : 0;
    switch (i.type) {
      case "directional":
        a = new e.DirectionalLight(l), a.target.position.set(0, 0, -1), a.add(a.target);
        break;
      case "point":
        a = new e.PointLight(l), a.distance = c;
        break;
      case "spot":
        a = new e.SpotLight(l), a.distance = c, i.spot = i.spot || {}, i.spot.innerConeAngle = void 0 !== i.spot.innerConeAngle ? i.spot.innerConeAngle : 0, i.spot.outerConeAngle = void 0 !== i.spot.outerConeAngle ? i.spot.outerConeAngle : Math.PI / 4, a.angle = i.spot.outerConeAngle, a.penumbra = 1 - i.spot.innerConeAngle / i.spot.outerConeAngle, a.target.position.set(0, 0, -1), a.add(a.target);
        break;
      default:
        throw new Error("THREE.GLTFLoader: Unexpected light type: " + i.type)
    }
    return a.position.set(0, 0, 0), a.decay = 2, void 0 !== i.intensity && (a.intensity = i.intensity), a.name = s.createUniqueName(i.name || "light_" + t), r = Promise.resolve(a), s.cache.add(n, r), r
  }
  createNodeAttachment(e) {
    const t = this,
      s = this.parser,
      n = s.json.nodes[e],
      r = (n.extensions && n.extensions[this.name] || {}).light;
    return void 0 === r ? null : this._loadLight(r).then((function (e) {
      return s._getNodeRef(t.cache, r, e)
    }))
  }
}
class i {
  constructor() {
    this.name = r.KHR_MATERIALS_UNLIT
  }
  getMaterialType() {
    return e.MeshBasicMaterial
  }
  extendParams(t, s, n) {
    const r = [];
    t.color = new e.Color(1, 1, 1), t.opacity = 1;
    const o = s.pbrMetallicRoughness;
    if (o) {
      if (Array.isArray(o.baseColorFactor)) {
        const e = o.baseColorFactor;
        t.color.fromArray(e), t.opacity = e[3]
      }
      void 0 !== o.baseColorTexture && r.push(n.assignTexture(t, "map", o.baseColorTexture))
    }
    return Promise.all(r)
  }
}
class a {
  constructor(e) {
    this.parser = e, this.name = r.KHR_MATERIALS_CLEARCOAT
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return s.extensions && s.extensions[this.name] ? e.MeshPhysicalMaterial : null
  }
  extendMaterialParams(t, s) {
    const n = this.parser,
      r = n.json.materials[t];
    if (!r.extensions || !r.extensions[this.name]) return Promise.resolve();
    const o = [],
      i = r.extensions[this.name];
    if (void 0 !== i.clearcoatFactor && (s.clearcoat = i.clearcoatFactor), void 0 !== i.clearcoatTexture && o.push(n.assignTexture(s, "clearcoatMap", i.clearcoatTexture)), void 0 !== i.clearcoatRoughnessFactor && (s.clearcoatRoughness = i.clearcoatRoughnessFactor), void 0 !== i.clearcoatRoughnessTexture && o.push(n.assignTexture(s, "clearcoatRoughnessMap", i.clearcoatRoughnessTexture)), void 0 !== i.clearcoatNormalTexture && (o.push(n.assignTexture(s, "clearcoatNormalMap", i.clearcoatNormalTexture)), void 0 !== i.clearcoatNormalTexture.scale)) {
      const t = i.clearcoatNormalTexture.scale;
      s.clearcoatNormalScale = new e.Vector2(t, t)
    }
    return Promise.all(o)
  }
}
class l {
  constructor(e) {
    this.parser = e, this.name = r.KHR_MATERIALS_TRANSMISSION
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return s.extensions && s.extensions[this.name] ? e.MeshPhysicalMaterial : null
  }
  extendMaterialParams(e, t) {
    const s = this.parser,
      n = s.json.materials[e];
    if (!n.extensions || !n.extensions[this.name]) return Promise.resolve();
    const r = [],
      o = n.extensions[this.name];
    return void 0 !== o.transmissionFactor && (t.transmission = o.transmissionFactor), void 0 !== o.transmissionTexture && r.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(r)
  }
}
class c {
  constructor(e) {
    this.parser = e, this.name = r.KHR_MATERIALS_VOLUME
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return s.extensions && s.extensions[this.name] ? e.MeshPhysicalMaterial : null
  }
  extendMaterialParams(t, s) {
    const n = this.parser,
      r = n.json.materials[t];
    if (!r.extensions || !r.extensions[this.name]) return Promise.resolve();
    const o = [],
      i = r.extensions[this.name];
    s.thickness = void 0 !== i.thicknessFactor ? i.thicknessFactor : 0, void 0 !== i.thicknessTexture && o.push(n.assignTexture(s, "thicknessMap", i.thicknessTexture)), s.attenuationDistance = i.attenuationDistance || 0;
    const a = i.attenuationColor || [1, 1, 1];
    return s.attenuationTint = new e.Color(a[0], a[1], a[2]), Promise.all(o)
  }
}
class u {
  constructor(e) {
    this.parser = e, this.name = r.KHR_MATERIALS_IOR
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return s.extensions && s.extensions[this.name] ? e.MeshPhysicalMaterial : null
  }
  extendMaterialParams(e, t) {
    const s = this.parser.json.materials[e];
    if (!s.extensions || !s.extensions[this.name]) return Promise.resolve();
    const n = s.extensions[this.name];
    return t.ior = void 0 !== n.ior ? n.ior : 1.5, Promise.resolve()
  }
}
class h {
  constructor(e) {
    this.parser = e, this.name = r.KHR_MATERIALS_SPECULAR
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return s.extensions && s.extensions[this.name] ? e.MeshPhysicalMaterial : null
  }
  extendMaterialParams(t, s) {
    const n = this.parser,
      r = n.json.materials[t];
    if (!r.extensions || !r.extensions[this.name]) return Promise.resolve();
    const o = [],
      i = r.extensions[this.name];
    s.specularIntensity = void 0 !== i.specularFactor ? i.specularFactor : 1, void 0 !== i.specularTexture && o.push(n.assignTexture(s, "specularIntensityMap", i.specularTexture));
    const a = i.specularColorFactor || [1, 1, 1];
    return s.specularTint = new e.Color(a[0], a[1], a[2]), void 0 !== i.specularColorTexture && o.push(n.assignTexture(s, "specularTintMap", i.specularColorTexture).then((function (t) {
      t.encoding = e.sRGBEncoding
    }))), Promise.all(o)
  }
}
class d {
  constructor(e) {
    this.parser = e, this.name = r.KHR_TEXTURE_BASISU
  }
  loadTexture(e) {
    const t = this.parser,
      s = t.json,
      n = s.textures[e];
    if (!n.extensions || !n.extensions[this.name]) return null;
    const r = n.extensions[this.name],
      o = s.images[r.source],
      i = t.options.ktx2Loader;
    if (!i) {
      if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
      return null
    }
    return t.loadTextureImage(e, o, i)
  }
}
class p {
  constructor(e) {
    this.parser = e, this.name = r.EXT_TEXTURE_WEBP, this.isSupported = null
  }
  loadTexture(e) {
    const t = this.name,
      s = this.parser,
      n = s.json,
      r = n.textures[e];
    if (!r.extensions || !r.extensions[t]) return null;
    const o = r.extensions[t],
      i = n.images[o.source];
    let a = s.textureLoader;
    if (i.uri) {
      const e = s.options.manager.getHandler(i.uri);
      null !== e && (a = e)
    }
    return this.detectSupport().then((function (r) {
      if (r) return s.loadTextureImage(e, i, a);
      if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0) throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
      return s.loadTexture(e)
    }))
  }
  detectSupport() {
    return this.isSupported || (this.isSupported = new Promise((function (e) {
      const t = new Image;
      t.src = "", t.onload = t.onerror = function () {
        e(1 === t.height)
      }
    }))), this.isSupported
  }
}
class m {
  constructor(e) {
    this.name = r.EXT_MESHOPT_COMPRESSION, this.parser = e
  }
  loadBufferView(e) {
    const t = this.parser.json,
      s = t.bufferViews[e];
    if (s.extensions && s.extensions[this.name]) {
      const e = s.extensions[this.name],
        n = this.parser.getDependency("buffer", e.buffer),
        r = this.parser.options.meshoptDecoder;
      if (!r || !r.supported) {
        if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
        return null
      }
      return Promise.all([n, r.ready]).then((function (t) {
        const s = e.byteOffset || 0,
          n = e.byteLength || 0,
          o = e.count,
          i = e.byteStride,
          a = new ArrayBuffer(o * i),
          l = new Uint8Array(t[0], s, n);
        return r.decodeGltfBuffer(new Uint8Array(a), o, i, l, e.mode, e.filter), a
      }))
    }
    return null
  }
}
const f = "glTF",
  g = 1313821514,
  T = 5130562;
class x {
  constructor(t) {
    this.name = r.KHR_BINARY_GLTF, this.content = null, this.body = null;
    const s = new DataView(t, 0, 12);
    if (this.header = {
        magic: e.LoaderUtils.decodeText(new Uint8Array(t.slice(0, 4))),
        version: s.getUint32(4, !0),
        length: s.getUint32(8, !0)
      }, this.header.magic !== f) throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
    if (this.header.version < 2) throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
    const n = this.header.length - 12,
      o = new DataView(t, 12);
    let i = 0;
    for (; i < n;) {
      const s = o.getUint32(i, !0);
      i += 4;
      const n = o.getUint32(i, !0);
      if (i += 4, n === g) {
        const n = new Uint8Array(t, 12 + i, s);
        this.content = e.LoaderUtils.decodeText(n)
      } else if (n === T) {
        const e = 12 + i;
        this.body = t.slice(e, e + s)
      }
      i += s
    }
    if (null === this.content) throw new Error("THREE.GLTFLoader: JSON content not found.")
  }
}
class M {
  constructor(e, t) {
    if (!t) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
    this.name = r.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload()
  }
  decodePrimitive(e, t) {
    const s = this.json,
      n = this.dracoLoader,
      r = e.extensions[this.name].bufferView,
      o = e.extensions[this.name].attributes,
      i = {},
      a = {},
      l = {};
    for (const e in o) {
      const t = k[e] || e.toLowerCase();
      i[t] = o[e]
    }
    for (const t in e.attributes) {
      const n = k[t] || t.toLowerCase();
      if (void 0 !== o[t]) {
        const r = s.accessors[e.attributes[t]],
          o = N[r.componentType];
        l[n] = o, a[n] = !0 === r.normalized
      }
    }
    return t.getDependency("bufferView", r).then((function (e) {
      return new Promise((function (t) {
        n.decodeDracoFile(e, (function (e) {
          for (const t in e.attributes) {
            const s = e.attributes[t],
              n = a[t];
            void 0 !== n && (s.normalized = n)
          }
          t(e)
        }), i, l)
      }))
    }))
  }
}
class v {
  constructor() {
    this.name = r.KHR_TEXTURE_TRANSFORM
  }
  extendTexture(e, t) {
    return void 0 !== t.texCoord && console.warn('THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.'), void 0 === t.offset && void 0 === t.rotation && void 0 === t.scale || (e = e.clone(), void 0 !== t.offset && e.offset.fromArray(t.offset), void 0 !== t.rotation && (e.rotation = t.rotation), void 0 !== t.scale && e.repeat.fromArray(t.scale), e.needsUpdate = !0), e
  }
}
class R extends e.MeshStandardMaterial {
  constructor(t) {
    super(), this.isGLTFSpecularGlossinessMaterial = !0;
    const s = ["#ifdef USE_SPECULARMAP", "\tuniform sampler2D specularMap;", "#endif"].join("\n"),
      n = ["#ifdef USE_GLOSSINESSMAP", "\tuniform sampler2D glossinessMap;", "#endif"].join("\n"),
      r = ["vec3 specularFactor = specular;", "#ifdef USE_SPECULARMAP", "\tvec4 texelSpecular = texture2D( specularMap, vUv );", "\ttexelSpecular = sRGBToLinear( texelSpecular );", "\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture", "\tspecularFactor *= texelSpecular.rgb;", "#endif"].join("\n"),
      o = ["float glossinessFactor = glossiness;", "#ifdef USE_GLOSSINESSMAP", "\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );", "\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture", "\tglossinessFactor *= texelGlossiness.a;", "#endif"].join("\n"),
      i = ["PhysicalMaterial material;", "material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );", "vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );", "float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );", "material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.", "material.roughness += geometryRoughness;", "material.roughness = min( material.roughness, 1.0 );", "material.specularColor = specularFactor;"].join("\n"),
      a = {
        specular: {
          value: (new e.Color).setHex(16777215)
        },
        glossiness: {
          value: 1
        },
        specularMap: {
          value: null
        },
        glossinessMap: {
          value: null
        }
      };
    this._extraUniforms = a, this.onBeforeCompile = function (e) {
      for (const t in a) e.uniforms[t] = a[t];
      e.fragmentShader = e.fragmentShader.replace("uniform float roughness;", "uniform vec3 specular;").replace("uniform float metalness;", "uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>", s).replace("#include <metalnessmap_pars_fragment>", n).replace("#include <roughnessmap_fragment>", r).replace("#include <metalnessmap_fragment>", o).replace("#include <lights_physical_fragment>", i)
    }, Object.defineProperties(this, {
      specular: {
        get: function () {
          return a.specular.value
        },
        set: function (e) {
          a.specular.value = e
        }
      },
      specularMap: {
        get: function () {
          return a.specularMap.value
        },
        set: function (e) {
          a.specularMap.value = e, e ? this.defines.USE_SPECULARMAP = "" : delete this.defines.USE_SPECULARMAP
        }
      },
      glossiness: {
        get: function () {
          return a.glossiness.value
        },
        set: function (e) {
          a.glossiness.value = e
        }
      },
      glossinessMap: {
        get: function () {
          return a.glossinessMap.value
        },
        set: function (e) {
          a.glossinessMap.value = e, e ? (this.defines.USE_GLOSSINESSMAP = "", this.defines.USE_UV = "") : (delete this.defines.USE_GLOSSINESSMAP, delete this.defines.USE_UV)
        }
      }
    }), delete this.metalness, delete this.roughness, delete this.metalnessMap, delete this.roughnessMap, this.setValues(t)
  }
  copy(e) {
    return super.copy(e), this.specularMap = e.specularMap, this.specular.copy(e.specular), this.glossinessMap = e.glossinessMap, this.glossiness = e.glossiness, delete this.metalness, delete this.roughness, delete this.metalnessMap, delete this.roughnessMap, this
  }
}
class S {
  constructor() {
    this.name = r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS, this.specularGlossinessParams = ["color", "map", "lightMap", "lightMapIntensity", "aoMap", "aoMapIntensity", "emissive", "emissiveIntensity", "emissiveMap", "bumpMap", "bumpScale", "normalMap", "normalMapType", "displacementMap", "displacementScale", "displacementBias", "specularMap", "specular", "glossinessMap", "glossiness", "alphaMap", "envMap", "envMapIntensity", "refractionRatio"]
  }
  getMaterialType() {
    return R
  }
  extendParams(t, s, n) {
    const r = s.extensions[this.name];
    t.color = new e.Color(1, 1, 1), t.opacity = 1;
    const o = [];
    if (Array.isArray(r.diffuseFactor)) {
      const e = r.diffuseFactor;
      t.color.fromArray(e), t.opacity = e[3]
    }
    if (void 0 !== r.diffuseTexture && o.push(n.assignTexture(t, "map", r.diffuseTexture)), t.emissive = new e.Color(0, 0, 0), t.glossiness = void 0 !== r.glossinessFactor ? r.glossinessFactor : 1, t.specular = new e.Color(1, 1, 1), Array.isArray(r.specularFactor) && t.specular.fromArray(r.specularFactor), void 0 !== r.specularGlossinessTexture) {
      const e = r.specularGlossinessTexture;
      o.push(n.assignTexture(t, "glossinessMap", e)), o.push(n.assignTexture(t, "specularMap", e))
    }
    return Promise.all(o)
  }
  createMaterial(t) {
    const s = new R(t);
    return s.fog = !0, s.color = t.color, s.map = void 0 === t.map ? null : t.map, s.lightMap = null, s.lightMapIntensity = 1, s.aoMap = void 0 === t.aoMap ? null : t.aoMap, s.aoMapIntensity = 1, s.emissive = t.emissive, s.emissiveIntensity = 1, s.emissiveMap = void 0 === t.emissiveMap ? null : t.emissiveMap, s.bumpMap = void 0 === t.bumpMap ? null : t.bumpMap, s.bumpScale = 1, s.normalMap = void 0 === t.normalMap ? null : t.normalMap, s.normalMapType = e.TangentSpaceNormalMap, t.normalScale && (s.normalScale = t.normalScale), s.displacementMap = null, s.displacementScale = 1, s.displacementBias = 0, s.specularMap = void 0 === t.specularMap ? null : t.specularMap, s.specular = t.specular, s.glossinessMap = void 0 === t.glossinessMap ? null : t.glossinessMap, s.glossiness = t.glossiness, s.alphaMap = null, s.envMap = void 0 === t.envMap ? null : t.envMap, s.envMapIntensity = 1, s.refractionRatio = .98, s
  }
}
class y {
  constructor() {
    this.name = r.KHR_MESH_QUANTIZATION
  }
}
class A extends e.Interpolant {
  constructor(e, t, s, n) {
    super(e, t, s, n)
  }
  copySampleValue_(e) {
    const t = this.resultBuffer,
      s = this.sampleValues,
      n = this.valueSize,
      r = e * n * 3 + n;
    for (let e = 0; e !== n; e++) t[e] = s[r + e];
    return t
  }
}
A.prototype.beforeStart_ = A.prototype.copySampleValue_, A.prototype.afterEnd_ = A.prototype.copySampleValue_, A.prototype.interpolate_ = function (e, t, s, n) {
  const r = this.resultBuffer,
    o = this.sampleValues,
    i = this.valueSize,
    a = 2 * i,
    l = 3 * i,
    c = n - t,
    u = (s - t) / c,
    h = u * u,
    d = h * u,
    p = e * l,
    m = p - l,
    f = -2 * d + 3 * h,
    g = d - h,
    T = 1 - f,
    x = g - h + u;
  for (let e = 0; e !== i; e++) {
    const t = o[m + e + i],
      s = o[m + e + a] * c,
      n = o[p + e + i],
      l = o[p + e] * c;
    r[e] = T * t + x * s + f * n + g * l
  }
  return r
};
const w = new e.Quaternion;
class _ extends A {
  interpolate_(e, t, s, n) {
    const r = super.interpolate_(e, t, s, n);
    return w.fromArray(r).normalize().toArray(r), r
  }
}
const E = 0,
  L = 1,
  b = 2,
  I = 3,
  P = 4,
  C = 5,
  O = 6,
  N = {
    5120: Int8Array,
    5121: Uint8Array,
    5122: Int16Array,
    5123: Uint16Array,
    5125: Uint32Array,
    5126: Float32Array
  },
  F = {
    9728: e.NearestFilter,
    9729: e.LinearFilter,
    9984: e.NearestMipmapNearestFilter,
    9985: e.LinearMipmapNearestFilter,
    9986: e.NearestMipmapLinearFilter,
    9987: e.LinearMipmapLinearFilter
  },
  U = {
    33071: e.ClampToEdgeWrapping,
    33648: e.MirroredRepeatWrapping,
    10497: e.RepeatWrapping
  },
  H = {
    SCALAR: 1,
    VEC2: 2,
    VEC3: 3,
    VEC4: 4,
    MAT2: 4,
    MAT3: 9,
    MAT4: 16
  },
  k = {
    POSITION: "position",
    NORMAL: "normal",
    TANGENT: "tangent",
    TEXCOORD_0: "uv",
    TEXCOORD_1: "uv2",
    COLOR_0: "color",
    WEIGHTS_0: "skinWeight",
    JOINTS_0: "skinIndex"
  },
  D = {
    scale: "scale",
    translation: "position",
    rotation: "quaternion",
    weights: "morphTargetInfluences"
  },
  G = {
    CUBICSPLINE: void 0,
    LINEAR: e.InterpolateLinear,
    STEP: e.InterpolateDiscrete
  },
  B = "OPAQUE",
  K = "MASK",
  j = "BLEND";

function V(e, t) {
  return "string" != typeof e || "" === e ? "" : (/^https?:\/\//i.test(t) && /^\//.test(e) && (t = t.replace(/(^https?:\/\/[^\/]+).*/i, "$1")), /^(https?:)?\/\//i.test(e) || /^data:.*,.*$/i.test(e) || /^blob:.*$/i.test(e) ? e : t + e)
}

function X(e, t, s) {
  for (const n in s.extensions) void 0 === e[n] && (t.userData.gltfExtensions = t.userData.gltfExtensions || {}, t.userData.gltfExtensions[n] = s.extensions[n])
}

function q(e, t) {
  void 0 !== t.extras && ("object" == typeof t.extras ? Object.assign(e.userData, t.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + t.extras))
}

function z(e, t) {
  if (e.updateMorphTargets(), void 0 !== t.weights)
    for (let s = 0, n = t.weights.length; s < n; s++) e.morphTargetInfluences[s] = t.weights[s];
  if (t.extras && Array.isArray(t.extras.targetNames)) {
    const s = t.extras.targetNames;
    if (e.morphTargetInfluences.length === s.length) {
      e.morphTargetDictionary = {};
      for (let t = 0, n = s.length; t < n; t++) e.morphTargetDictionary[s[t]] = t
    } else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")
  }
}

function W(e) {
  const t = e.extensions && e.extensions[r.KHR_DRACO_MESH_COMPRESSION];
  let s;
  return s = t ? "draco:" + t.bufferView + ":" + t.indices + ":" + Q(t.attributes) : e.indices + ":" + Q(e.attributes) + ":" + e.mode, s
}

function Q(e) {
  let t = "";
  const s = Object.keys(e).sort();
  for (let n = 0, r = s.length; n < r; n++) t += s[n] + ":" + e[s[n]] + ";";
  return t
}

function Y(e) {
  switch (e) {
    case Int8Array:
      return 1 / 127;
    case Uint8Array:
      return 1 / 255;
    case Int16Array:
      return 1 / 32767;
    case Uint16Array:
      return 1 / 65535;
    default:
      throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")
  }
}
class $ {
  constructor(t = {}, s = {}) {
    this.json = t, this.extensions = {}, this.plugins = {}, this.options = s, this.cache = new n, this.associations = new Map, this.primitiveCache = {}, this.meshCache = {
      refs: {},
      uses: {}
    }, this.cameraCache = {
      refs: {},
      uses: {}
    }, this.lightCache = {
      refs: {},
      uses: {}
    }, this.textureCache = {}, this.nodeNamesUsed = {}, void 0 !== e.$createImageBitmap && !1 === /Firefox/.test(navigator.userAgent) ? this.textureLoader = new e.ImageBitmapLoader(this.options.manager) : this.textureLoader = new e.TextureLoader(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new e.FileLoader(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), "use-credentials" === this.options.crossOrigin && this.fileLoader.setWithCredentials(!0)
  }
  setExtensions(e) {
    this.extensions = e
  }
  setPlugins(e) {
    this.plugins = e
  }
  parse(e, t) {
    const s = this,
      n = this.json,
      r = this.extensions;
    this.cache.removeAll(), this._invokeAll((function (e) {
      return e._markDefs && e._markDefs()
    })), Promise.all(this._invokeAll((function (e) {
      return e.beforeRoot && e.beforeRoot()
    }))).then((function () {
      return Promise.all([s.getDependencies("scene"), s.getDependencies("animation"), s.getDependencies("camera")])
    })).then((function (t) {
      const o = {
        scene: t[0][n.scene || 0],
        scenes: t[0],
        animations: t[1],
        cameras: t[2],
        asset: n.asset,
        parser: s,
        userData: {}
      };
      X(r, o, n), q(o, n), Promise.all(s._invokeAll((function (e) {
        return e.afterRoot && e.afterRoot(o)
      }))).then((function () {
        e(o)
      }))
    })).catch(t)
  }
  _markDefs() {
    const e = this.json.nodes || [],
      t = this.json.skins || [],
      s = this.json.meshes || [];
    for (let s = 0, n = t.length; s < n; s++) {
      const n = t[s].joints;
      for (let t = 0, s = n.length; t < s; t++) e[n[t]].isBone = !0
    }
    for (let t = 0, n = e.length; t < n; t++) {
      const n = e[t];
      void 0 !== n.mesh && (this._addNodeRef(this.meshCache, n.mesh), void 0 !== n.skin && (s[n.mesh].isSkinnedMesh = !0)), void 0 !== n.camera && this._addNodeRef(this.cameraCache, n.camera)
    }
  }
  _addNodeRef(e, t) {
    void 0 !== t && (void 0 === e.refs[t] && (e.refs[t] = e.uses[t] = 0), e.refs[t]++)
  }
  _getNodeRef(e, t, s) {
    if (e.refs[t] <= 1) return s;
    const n = s.clone(),
      r = (e, t) => {
        const s = this.associations.get(e);
        null != s && this.associations.set(t, s);
        for (const [s, n] of e.children.entries()) r(n, t.children[s])
      };
    return r(s, n), n.name += "_instance_" + e.uses[t]++, n
  }
  _invokeOne(e) {
    const t = Object.values(this.plugins);
    t.push(this);
    for (let s = 0; s < t.length; s++) {
      const n = e(t[s]);
      if (n) return n
    }
    return null
  }
  _invokeAll(e) {
    const t = Object.values(this.plugins);
    t.unshift(this);
    const s = [];
    for (let n = 0; n < t.length; n++) {
      const r = e(t[n]);
      r && s.push(r)
    }
    return s
  }
  getDependency(e, t) {
    const s = e + ":" + t;
    let n = this.cache.get(s);
    if (!n) {
      switch (e) {
        case "scene":
          n = this.loadScene(t);
          break;
        case "node":
          n = this.loadNode(t);
          break;
        case "mesh":
          n = this._invokeOne((function (e) {
            return e.loadMesh && e.loadMesh(t)
          }));
          break;
        case "accessor":
          n = this.loadAccessor(t);
          break;
        case "bufferView":
          n = this._invokeOne((function (e) {
            return e.loadBufferView && e.loadBufferView(t)
          }));
          break;
        case "buffer":
          n = this.loadBuffer(t);
          break;
        case "material":
          n = this._invokeOne((function (e) {
            return e.loadMaterial && e.loadMaterial(t)
          }));
          break;
        case "texture":
          n = this._invokeOne((function (e) {
            return e.loadTexture && e.loadTexture(t)
          }));
          break;
        case "skin":
          n = this.loadSkin(t);
          break;
        case "animation":
          n = this.loadAnimation(t);
          break;
        case "camera":
          n = this.loadCamera(t);
          break;
        default:
          throw new Error("Unknown type: " + e)
      }
      this.cache.add(s, n)
    }
    return n
  }
  getDependencies(e) {
    let t = this.cache.get(e);
    if (!t) {
      const s = this,
        n = this.json[e + ("mesh" === e ? "es" : "s")] || [];
      t = Promise.all(n.map((function (t, n) {
        return s.getDependency(e, n)
      }))), this.cache.add(e, t)
    }
    return t
  }
  loadBuffer(e) {
    const t = this.json.buffers[e],
      s = this.fileLoader;
    if (t.type && "arraybuffer" !== t.type) throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported.");
    if (void 0 === t.uri && 0 === e) return Promise.resolve(this.extensions[r.KHR_BINARY_GLTF].body);
    const n = this.options;
    return new Promise((function (e, r) {
      s.load(V(t.uri, n.path), e, void 0, (function () {
        r(new Error('THREE.GLTFLoader: Failed to load buffer "' + t.uri + '".'))
      }))
    }))
  }
  loadBufferView(e) {
    const t = this.json.bufferViews[e];
    return this.getDependency("buffer", t.buffer).then((function (e) {
      const s = t.byteLength || 0,
        n = t.byteOffset || 0;
      return e.slice(n, n + s)
    }))
  }
  loadAccessor(t) {
    const s = this,
      n = this.json,
      r = this.json.accessors[t];
    if (void 0 === r.bufferView && void 0 === r.sparse) return Promise.resolve(null);
    const o = [];
    return void 0 !== r.bufferView ? o.push(this.getDependency("bufferView", r.bufferView)) : o.push(null), void 0 !== r.sparse && (o.push(this.getDependency("bufferView", r.sparse.indices.bufferView)), o.push(this.getDependency("bufferView", r.sparse.values.bufferView))), Promise.all(o).then((function (t) {
      const o = t[0],
        i = H[r.type],
        a = N[r.componentType],
        l = a.BYTES_PER_ELEMENT,
        c = l * i,
        u = r.byteOffset || 0,
        h = void 0 !== r.bufferView ? n.bufferViews[r.bufferView].byteStride : void 0,
        d = !0 === r.normalized;
      let p, m;
      if (h && h !== c) {
        const t = Math.floor(u / h),
          n = "InterleavedBuffer:" + r.bufferView + ":" + r.componentType + ":" + t + ":" + r.count;
        let c = s.cache.get(n);
        c || (p = new a(o, t * h, r.count * h / l), c = new e.InterleavedBuffer(p, h / l), s.cache.add(n, c)), m = new e.InterleavedBufferAttribute(c, i, u % h / l, d)
      } else p = null === o ? new a(r.count * i) : new a(o, u, r.count * i), m = new e.BufferAttribute(p, i, d);
      if (void 0 !== r.sparse) {
        const s = H.SCALAR,
          n = N[r.sparse.indices.componentType],
          l = r.sparse.indices.byteOffset || 0,
          c = r.sparse.values.byteOffset || 0,
          u = new n(t[1], l, r.sparse.count * s),
          h = new a(t[2], c, r.sparse.count * i);
        null !== o && (m = new e.BufferAttribute(m.array.slice(), m.itemSize, m.normalized));
        for (let e = 0, t = u.length; e < t; e++) {
          const t = u[e];
          if (m.setX(t, h[e * i]), i >= 2 && m.setY(t, h[e * i + 1]), i >= 3 && m.setZ(t, h[e * i + 2]), i >= 4 && m.setW(t, h[e * i + 3]), i >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")
        }
      }
      return m
    }))
  }
  loadTexture(e) {
    const t = this.json,
      s = this.options,
      n = t.textures[e],
      r = t.images[n.source];
    let o = this.textureLoader;
    if (r.uri) {
      const e = s.manager.getHandler(r.uri);
      null !== e && (o = e)
    }
    return this.loadTextureImage(e, r, o)
  }
  loadTextureImage(t, s, n) {
    const r = this,
      o = this.json,
      i = this.options,
      a = o.textures[t],
      l = (s.uri || s.bufferView) + ":" + a.sampler;
    if (this.textureCache[l]) return this.textureCache[l];
    const c = e.$URL || self.webkitURL;
    let u = s.uri || "",
      h = !1;
    if (void 0 !== s.bufferView) u = r.getDependency("bufferView", s.bufferView).then((function (t) {
      h = !0;
      const n = new e.$Blob([t], {
        type: s.mimeType
      });
      return u = c.createObjectURL(n), u
    }));
    else if (void 0 === s.uri) throw new Error("THREE.GLTFLoader: Image " + t + " is missing URI and bufferView");
    const d = Promise.resolve(u).then((function (t) {
      return new Promise((function (s, r) {
        let o = s;
        !0 === n.isImageBitmapLoader && (o = function (t) {
          const n = new e.Texture(t);
          n.needsUpdate = !0, s(n)
        }), n.load(V(t, i.path), o, void 0, r)
      }))
    })).then((function (s) {
      !0 === h && c.revokeObjectURL(u), s.flipY = !1, a.name && (s.name = a.name);
      const n = (o.samplers || {})[a.sampler] || {};
      return s.magFilter = F[n.magFilter] || e.LinearFilter, s.minFilter = F[n.minFilter] || e.LinearMipmapLinearFilter, s.wrapS = U[n.wrapS] || e.RepeatWrapping, s.wrapT = U[n.wrapT] || e.RepeatWrapping, r.associations.set(s, {
        textures: t
      }), s
    })).catch((function () {
      return console.error("THREE.GLTFLoader: Couldn't load texture", u), null
    }));
    return this.textureCache[l] = d, d
  }
  assignTexture(e, t, s) {
    const n = this;
    return this.getDependency("texture", s.index).then((function (o) {
      if (void 0 === s.texCoord || 0 == s.texCoord || "aoMap" === t && 1 == s.texCoord || console.warn("THREE.GLTFLoader: Custom UV set " + s.texCoord + " for texture " + t + " not yet supported."), n.extensions[r.KHR_TEXTURE_TRANSFORM]) {
        const e = void 0 !== s.extensions ? s.extensions[r.KHR_TEXTURE_TRANSFORM] : void 0;
        if (e) {
          const t = n.associations.get(o);
          o = n.extensions[r.KHR_TEXTURE_TRANSFORM].extendTexture(o, e), n.associations.set(o, t)
        }
      }
      return e[t] = o, o
    }))
  }
  assignFinalMaterial(t) {
    const s = t.geometry;
    let n = t.material;
    const r = void 0 === s.attributes.tangent,
      o = void 0 !== s.attributes.color,
      i = void 0 === s.attributes.normal;
    if (t.isPoints) {
      const t = "PointsMaterial:" + n.uuid;
      let s = this.cache.get(t);
      s || (s = new e.PointsMaterial, e.Material.prototype.copy.call(s, n), s.color.copy(n.color), s.map = n.map, s.sizeAttenuation = !1, this.cache.add(t, s)), n = s
    } else if (t.isLine) {
      const t = "LineBasicMaterial:" + n.uuid;
      let s = this.cache.get(t);
      s || (s = new e.LineBasicMaterial, e.Material.prototype.copy.call(s, n), s.color.copy(n.color), this.cache.add(t, s)), n = s
    }
    if (r || o || i) {
      let e = "ClonedMaterial:" + n.uuid + ":";
      n.isGLTFSpecularGlossinessMaterial && (e += "specular-glossiness:"), r && (e += "derivative-tangents:"), o && (e += "vertex-colors:"), i && (e += "flat-shading:");
      let t = this.cache.get(e);
      t || (t = n.clone(), o && (t.vertexColors = !0), i && (t.flatShading = !0), r && (t.normalScale && (t.normalScale.y *= -1), t.clearcoatNormalScale && (t.clearcoatNormalScale.y *= -1)), this.cache.add(e, t), this.associations.set(t, this.associations.get(n))), n = t
    }
    n.aoMap && void 0 === s.attributes.uv2 && void 0 !== s.attributes.uv && s.setAttribute("uv2", s.attributes.uv), t.material = n
  }
  getMaterialType() {
    return e.MeshStandardMaterial
  }
  loadMaterial(t) {
    const s = this,
      n = this.json,
      o = this.extensions,
      i = n.materials[t];
    let a;
    const l = {},
      c = i.extensions || {},
      u = [];
    if (c[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
      const e = o[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
      a = e.getMaterialType(), u.push(e.extendParams(l, i, s))
    } else if (c[r.KHR_MATERIALS_UNLIT]) {
      const e = o[r.KHR_MATERIALS_UNLIT];
      a = e.getMaterialType(), u.push(e.extendParams(l, i, s))
    } else {
      const n = i.pbrMetallicRoughness || {};
      if (l.color = new e.Color(1, 1, 1), l.opacity = 1, Array.isArray(n.baseColorFactor)) {
        const e = n.baseColorFactor;
        l.color.fromArray(e), l.opacity = e[3]
      }
      void 0 !== n.baseColorTexture && u.push(s.assignTexture(l, "map", n.baseColorTexture)), l.metalness = void 0 !== n.metallicFactor ? n.metallicFactor : 1, l.roughness = void 0 !== n.roughnessFactor ? n.roughnessFactor : 1, void 0 !== n.metallicRoughnessTexture && (u.push(s.assignTexture(l, "metalnessMap", n.metallicRoughnessTexture)), u.push(s.assignTexture(l, "roughnessMap", n.metallicRoughnessTexture))), a = this._invokeOne((function (e) {
        return e.getMaterialType && e.getMaterialType(t)
      })), u.push(Promise.all(this._invokeAll((function (e) {
        return e.extendMaterialParams && e.extendMaterialParams(t, l)
      }))))
    }!0 === i.doubleSided && (l.side = e.DoubleSide);
    const h = i.alphaMode || B;
    if (h === j ? (l.transparent = !0, l.depthWrite = !1) : (l.format = e.RGBFormat, l.transparent = !1, h === K && (l.alphaTest = void 0 !== i.alphaCutoff ? i.alphaCutoff : .5)), void 0 !== i.normalTexture && a !== e.MeshBasicMaterial && (u.push(s.assignTexture(l, "normalMap", i.normalTexture)), l.normalScale = new e.Vector2(1, 1), void 0 !== i.normalTexture.scale)) {
      const e = i.normalTexture.scale;
      l.normalScale.set(e, e)
    }
    return void 0 !== i.occlusionTexture && a !== e.MeshBasicMaterial && (u.push(s.assignTexture(l, "aoMap", i.occlusionTexture)), void 0 !== i.occlusionTexture.strength && (l.aoMapIntensity = i.occlusionTexture.strength)), void 0 !== i.emissiveFactor && a !== e.MeshBasicMaterial && (l.emissive = (new e.Color).fromArray(i.emissiveFactor)), void 0 !== i.emissiveTexture && a !== e.MeshBasicMaterial && u.push(s.assignTexture(l, "emissiveMap", i.emissiveTexture)), Promise.all(u).then((function () {
      let n;
      return n = a === R ? o[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l) : new a(l), i.name && (n.name = i.name), n.map && (n.map.encoding = e.sRGBEncoding), n.emissiveMap && (n.emissiveMap.encoding = e.sRGBEncoding), q(n, i), s.associations.set(n, {
        materials: t
      }), i.extensions && X(o, n, i), n
    }))
  }
  createUniqueName(t) {
    const s = e.PropertyBinding.sanitizeNodeName(t || "");
    let n = s;
    for (let e = 1; this.nodeNamesUsed[n]; ++e) n = s + "_" + e;
    return this.nodeNamesUsed[n] = !0, n
  }
  loadGeometries(t) {
    const s = this,
      n = this.extensions,
      o = this.primitiveCache;

    function i(e) {
      return n[r.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e, s).then((function (t) {
        return Z(t, e, s)
      }))
    }
    const a = [];
    for (let n = 0, l = t.length; n < l; n++) {
      const l = t[n],
        c = W(l),
        u = o[c];
      if (u) a.push(u.promise);
      else {
        let t;
        t = l.extensions && l.extensions[r.KHR_DRACO_MESH_COMPRESSION] ? i(l) : Z(new e.BufferGeometry, l, s), o[c] = {
          primitive: l,
          promise: t
        }, a.push(t)
      }
    }
    return Promise.all(a)
  }
  loadMesh(t) {
    const s = this,
      n = this.json,
      r = this.extensions,
      o = n.meshes[t],
      i = o.primitives,
      a = [];
    for (let t = 0, s = i.length; t < s; t++) {
      const s = void 0 === i[t].material ? (void 0 === (l = this.cache).DefaultMaterial && (l.DefaultMaterial = new e.MeshStandardMaterial({
        color: 16777215,
        emissive: 0,
        metalness: 1,
        roughness: 1,
        transparent: !1,
        depthTest: !0,
        side: e.FrontSide
      })), l.DefaultMaterial) : this.getDependency("material", i[t].material);
      a.push(s)
    }
    var l;
    return a.push(s.loadGeometries(i)), Promise.all(a).then((function (n) {
      const a = n.slice(0, n.length - 1),
        l = n[n.length - 1],
        c = [];
      for (let n = 0, u = l.length; n < u; n++) {
        const u = l[n],
          h = i[n];
        let d;
        const p = a[n];
        if (h.mode === P || h.mode === C || h.mode === O || void 0 === h.mode) d = !0 === o.isSkinnedMesh ? new e.SkinnedMesh(u, p) : new e.Mesh(u, p), !0 !== d.isSkinnedMesh || d.geometry.attributes.skinWeight.normalized || d.normalizeSkinWeights(), h.mode === C ? d.geometry = ee(d.geometry, e.TriangleStripDrawMode) : h.mode === O && (d.geometry = ee(d.geometry, e.TriangleFanDrawMode));
        else if (h.mode === L) d = new e.LineSegments(u, p);
        else if (h.mode === I) d = new e.Line(u, p);
        else if (h.mode === b) d = new e.LineLoop(u, p);
        else {
          if (h.mode !== E) throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + h.mode);
          d = new e.Points(u, p)
        }
        Object.keys(d.geometry.morphAttributes).length > 0 && z(d, o), d.name = s.createUniqueName(o.name || "mesh_" + t), q(d, o), h.extensions && X(r, d, h), s.assignFinalMaterial(d), c.push(d)
      }
      for (let e = 0, n = c.length; e < n; e++) s.associations.set(c[e], {
        meshes: t,
        primitives: e
      });
      if (1 === c.length) return c[0];
      const u = new e.Group;
      s.associations.set(u, {
        meshes: t
      });
      for (let e = 0, t = c.length; e < t; e++) u.add(c[e]);
      return u
    }))
  }
  loadCamera(t) {
    let s;
    const n = this.json.cameras[t],
      r = n[n.type];
    if (r) return "perspective" === n.type ? s = new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov), r.aspectRatio || 1, r.znear || 1, r.zfar || 2e6) : "orthographic" === n.type && (s = new e.OrthographicCamera(-r.xmag, r.xmag, r.ymag, -r.ymag, r.znear, r.zfar)), n.name && (s.name = this.createUniqueName(n.name)), q(s, n), Promise.resolve(s);
    console.warn("THREE.GLTFLoader: Missing camera parameters.")
  }
  loadSkin(e) {
    const t = this.json.skins[e],
      s = {
        joints: t.joints
      };
    return void 0 === t.inverseBindMatrices ? Promise.resolve(s) : this.getDependency("accessor", t.inverseBindMatrices).then((function (e) {
      return s.inverseBindMatrices = e, s
    }))
  }
  loadAnimation(t) {
    const s = this.json.animations[t],
      n = [],
      r = [],
      o = [],
      i = [],
      a = [];
    for (let e = 0, t = s.channels.length; e < t; e++) {
      const t = s.channels[e],
        l = s.samplers[t.sampler],
        c = t.target,
        u = void 0 !== c.node ? c.node : c.id,
        h = void 0 !== s.parameters ? s.parameters[l.input] : l.input,
        d = void 0 !== s.parameters ? s.parameters[l.output] : l.output;
      n.push(this.getDependency("node", u)), r.push(this.getDependency("accessor", h)), o.push(this.getDependency("accessor", d)), i.push(l), a.push(c)
    }
    return Promise.all([Promise.all(n), Promise.all(r), Promise.all(o), Promise.all(i), Promise.all(a)]).then((function (n) {
      const r = n[0],
        o = n[1],
        i = n[2],
        a = n[3],
        l = n[4],
        c = [];
      for (let t = 0, s = r.length; t < s; t++) {
        const s = r[t],
          n = o[t],
          u = i[t],
          h = a[t],
          d = l[t];
        if (void 0 === s) continue;
        let p;
        switch (s.updateMatrix(), s.matrixAutoUpdate = !0, D[d.path]) {
          case D.weights:
            p = e.NumberKeyframeTrack;
            break;
          case D.rotation:
            p = e.QuaternionKeyframeTrack;
            break;
          default:
            p = e.VectorKeyframeTrack
        }
        const m = s.name ? s.name : s.uuid,
          f = void 0 !== h.interpolation ? G[h.interpolation] : e.InterpolateLinear,
          g = [];
        D[d.path] === D.weights ? s.traverse((function (e) {
          !0 === e.isMesh && e.morphTargetInfluences && g.push(e.name ? e.name : e.uuid)
        })) : g.push(m);
        let T = u.array;
        if (u.normalized) {
          const e = Y(T.constructor),
            t = new Float32Array(T.length);
          for (let s = 0, n = T.length; s < n; s++) t[s] = T[s] * e;
          T = t
        }
        for (let t = 0, s = g.length; t < s; t++) {
          const s = new p(g[t] + "." + D[d.path], n.array, T, f);
          "CUBICSPLINE" === h.interpolation && (s.createInterpolant = function (t) {
            return new(this instanceof e.QuaternionKeyframeTrack ? _ : A)(this.times, this.values, this.getValueSize() / 3, t)
          }, s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0), c.push(s)
        }
      }
      const u = s.name ? s.name : "animation_" + t;
      return new e.AnimationClip(u, void 0, c)
    }))
  }
  createNodeMesh(e) {
    const t = this.json,
      s = this,
      n = t.nodes[e];
    return void 0 === n.mesh ? null : s.getDependency("mesh", n.mesh).then((function (e) {
      const t = s._getNodeRef(s.meshCache, n.mesh, e);
      return void 0 !== n.weights && t.traverse((function (e) {
        if (e.isMesh)
          for (let t = 0, s = n.weights.length; t < s; t++) e.morphTargetInfluences[t] = n.weights[t]
      })), t
    }))
  }
  loadNode(t) {
    const s = this.json,
      n = this.extensions,
      r = this,
      o = s.nodes[t],
      i = o.name ? r.createUniqueName(o.name) : "";
    return function () {
      const e = [],
        s = r._invokeOne((function (e) {
          return e.createNodeMesh && e.createNodeMesh(t)
        }));
      return s && e.push(s), void 0 !== o.camera && e.push(r.getDependency("camera", o.camera).then((function (e) {
        return r._getNodeRef(r.cameraCache, o.camera, e)
      }))), r._invokeAll((function (e) {
        return e.createNodeAttachment && e.createNodeAttachment(t)
      })).forEach((function (t) {
        e.push(t)
      })), Promise.all(e)
    }().then((function (s) {
      let a;
      if (a = !0 === o.isBone ? new e.Bone : s.length > 1 ? new e.Group : 1 === s.length ? s[0] : new e.Object3D, a !== s[0])
        for (let e = 0, t = s.length; e < t; e++) a.add(s[e]);
      if (o.name && (a.userData.name = o.name, a.name = i), q(a, o), o.extensions && X(n, a, o), void 0 !== o.matrix) {
        const t = new e.Matrix4;
        t.fromArray(o.matrix), a.applyMatrix4(t)
      } else void 0 !== o.translation && a.position.fromArray(o.translation), void 0 !== o.rotation && a.quaternion.fromArray(o.rotation), void 0 !== o.scale && a.scale.fromArray(o.scale);
      return r.associations.has(a) || r.associations.set(a, {}), r.associations.get(a).nodes = t, a
    }))
  }
  loadScene(t) {
    const s = this.json,
      n = this.extensions,
      r = this.json.scenes[t],
      o = this,
      i = new e.Group;
    r.name && (i.name = o.createUniqueName(r.name)), q(i, r), r.extensions && X(n, i, r);
    const a = r.nodes || [],
      l = [];
    for (let e = 0, t = a.length; e < t; e++) l.push(J(a[e], i, s, o));
    return Promise.all(l).then((function () {
      return o.associations = (t => {
        const s = new Map;
        for (const [t, n] of o.associations)(t instanceof e.Material || t instanceof e.Texture) && s.set(t, n);
        return t.traverse((e => {
          const t = o.associations.get(e);
          null != t && s.set(e, t)
        })), s
      })(i), i
    }))
  }
}

function J(t, s, n, r) {
  const o = n.nodes[t];
  return r.getDependency("node", t).then((function (t) {
    if (void 0 === o.skin) return t;
    let s;
    return r.getDependency("skin", o.skin).then((function (e) {
      s = e;
      const t = [];
      for (let e = 0, n = s.joints.length; e < n; e++) t.push(r.getDependency("node", s.joints[e]));
      return Promise.all(t)
    })).then((function (n) {
      return t.traverse((function (t) {
        if (!t.isMesh) return;
        const r = [],
          o = [];
        for (let t = 0, i = n.length; t < i; t++) {
          const i = n[t];
          if (i) {
            r.push(i);
            const n = new e.Matrix4;
            void 0 !== s.inverseBindMatrices && n.fromArray(s.inverseBindMatrices.array, 16 * t), o.push(n)
          } else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', s.joints[t])
        }
        t.bind(new e.Skeleton(r, o), t.matrixWorld)
      })), t
    }))
  })).then((function (e) {
    s.add(e);
    const t = [];
    if (o.children) {
      const s = o.children;
      for (let o = 0, i = s.length; o < i; o++) {
        const i = s[o];
        t.push(J(i, e, n, r))
      }
    }
    return Promise.all(t)
  }))
}

function Z(t, s, n) {
  const r = s.attributes,
    o = [];

  function i(e, s) {
    return n.getDependency("accessor", e).then((function (e) {
      t.setAttribute(s, e)
    }))
  }
  for (const e in r) {
    const s = k[e] || e.toLowerCase();
    s in t.attributes || o.push(i(r[e], s))
  }
  if (void 0 !== s.indices && !t.index) {
    const e = n.getDependency("accessor", s.indices).then((function (e) {
      t.setIndex(e)
    }));
    o.push(e)
  }
  return q(t, s),
    function (t, s, n) {
      const r = s.attributes,
        o = new e.Box3;
      if (void 0 === r.POSITION) return; {
        const t = n.json.accessors[r.POSITION],
          s = t.min,
          i = t.max;
        if (void 0 === s || void 0 === i) return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
        if (o.set(new e.Vector3(s[0], s[1], s[2]), new e.Vector3(i[0], i[1], i[2])), t.normalized) {
          const e = Y(N[t.componentType]);
          o.min.multiplyScalar(e), o.max.multiplyScalar(e)
        }
      }
      const i = s.targets;
      if (void 0 !== i) {
        const t = new e.Vector3,
          s = new e.Vector3;
        for (let e = 0, r = i.length; e < r; e++) {
          const r = i[e];
          if (void 0 !== r.POSITION) {
            const e = n.json.accessors[r.POSITION],
              o = e.min,
              i = e.max;
            if (void 0 !== o && void 0 !== i) {
              if (s.setX(Math.max(Math.abs(o[0]), Math.abs(i[0]))), s.setY(Math.max(Math.abs(o[1]), Math.abs(i[1]))), s.setZ(Math.max(Math.abs(o[2]), Math.abs(i[2]))), e.normalized) {
                const t = Y(N[e.componentType]);
                s.multiplyScalar(t)
              }
              t.max(s)
            } else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")
          }
        }
        o.expandByVector(t)
      }
      t.boundingBox = o;
      const a = new e.Sphere;
      o.getCenter(a.center), a.radius = o.min.distanceTo(o.max) / 2, t.boundingSphere = a
    }(t, s, n), Promise.all(o).then((function () {
      return void 0 !== s.targets ? function (e, t, s) {
        let n = !1,
          r = !1;
        for (let e = 0, s = t.length; e < s; e++) {
          const s = t[e];
          if (void 0 !== s.POSITION && (n = !0), void 0 !== s.NORMAL && (r = !0), n && r) break
        }
        if (!n && !r) return Promise.resolve(e);
        const o = [],
          i = [];
        for (let a = 0, l = t.length; a < l; a++) {
          const l = t[a];
          if (n) {
            const t = void 0 !== l.POSITION ? s.getDependency("accessor", l.POSITION) : e.attributes.position;
            o.push(t)
          }
          if (r) {
            const t = void 0 !== l.NORMAL ? s.getDependency("accessor", l.NORMAL) : e.attributes.normal;
            i.push(t)
          }
        }
        return Promise.all([Promise.all(o), Promise.all(i)]).then((function (t) {
          const s = t[0],
            o = t[1];
          return n && (e.morphAttributes.position = s), r && (e.morphAttributes.normal = o), e.morphTargetsRelative = !0, e
        }))
      }(t, s.targets, n) : t
    }))
}

function ee(t, s) {
  let n = t.getIndex();
  if (null === n) {
    const e = [],
      s = t.getAttribute("position");
    if (void 0 === s) return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), t;
    for (let t = 0; t < s.count; t++) e.push(t);
    t.setIndex(e), n = t.getIndex()
  }
  const r = n.count - 2,
    o = [];
  if (s === e.TriangleFanDrawMode)
    for (let e = 1; e <= r; e++) o.push(n.getX(0)), o.push(n.getX(e)), o.push(n.getX(e + 1));
  else
    for (let e = 0; e < r; e++) e % 2 == 0 ? (o.push(n.getX(e)), o.push(n.getX(e + 1)), o.push(n.getX(e + 2))) : (o.push(n.getX(e + 2)), o.push(n.getX(e + 1)), o.push(n.getX(e)));
  o.length / 3 !== r && console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
  const i = t.clone();
  return i.setIndex(o), i
}
Page({
  source:'',
  modelId: "",
  modelSrc: "",
  disposing: !1,
  platform: null,
  frameId: -1,
  onToMoney() {
    wx.navigateTo({
      url: "/pages/order/placeOrder?pageType=single&id=" + this.modelId
    })
  },
  onLoad(e) {
    console.log("模型参数：", e), this.modelId = e.modelId, this.modelSrc = decodeURIComponent(e.modelSrc),
    this.setData({
      source:e.source
    })
  },
  async onReady() {
    wx.showLoading({
      mask: !1,
      title: "加载中"
    }), wx.createSelectorQuery().select("#gl").node().exec((async n => {
      const r = n[0].node;
      this.platform = new t.WechatPlatform(r), e.PLATFORM.set(this.platform);
      const o = new e.WebGL1Renderer({
          canvas: r,
          antialias: !0,
          alpha: !0
        }),
        i = new e.PerspectiveCamera(75, r.width / r.height, .1, 1e3),
        a = new e.Scene,
        l = new s,
        c = new t.OrbitControls(i, r);
      c.enableDamping = !0;
      let u = await l.loadAsync(this.modelSrc);
      u.parser = null, a.add(u.scene), i.position.z = 1, o.outputEncoding = e.sRGBEncoding, a.add(new e.AmbientLight(16777215, 1)), a.add(new e.DirectionalLight(16777215, 1)), o.setSize(r.width, r.height), o.setPixelRatio(e.$window.devicePixelRatio);
      const h = () => {
        this.disposing || (this.frameId = e.$requestAnimationFrame(h)), c.update(), o.render(a, i)
      };
      h(), wx.hideLoading()
    }))
  },
  onUnload() {
    this.disposing = !0, e.$cancelAnimationFrame(this.frameId), e.PLATFORM.dispose()
  },
  onTX(e) {
    this.platform.dispatchTouchEvent(e)
  },
  
  onShareAppMessage(){
    let modelSrc = encodeURIComponent(this.modelSrc);
    let path= '/pages/preview/single?modelId=' + this.modelId + '&modelSrc=' + modelSrc+'&source=share';
    return {
      title: '3D人像',
      path: path
    }
  }
});